/**
 * LogKaiyuanTurnoverService.java
 * Copyright(C) 1949++ 中华人民共和国
 * 深圳市盛开互联网金融顾问有限公司.
 * All rights reserved.
 * E-mail:server@skjr.net
 * SKDate:2017-11-16 17:28:58
 */
package com.huamao.zh.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huamao.zh.base.PageWrapper;
import com.huamao.zh.constants.KaiyuanTurnoverType;
import com.huamao.zh.mapper.LogKaiyuanTurnoverMapper;
import com.huamao.zh.model.LogKaiyuanTurnover;
import com.huamao.zh.service.LogKaiyuanTurnoverService;

@Service
@Transactional
public class LogKaiyuanTurnoverServiceImpl implements LogKaiyuanTurnoverService {

	@Autowired
	private LogKaiyuanTurnoverMapper logKaiyuanTurnoverMapper;

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanTurnover add(LogKaiyuanTurnover logKaiyuanTurnover) throws Exception {
		logKaiyuanTurnoverMapper.add(logKaiyuanTurnover);
		return logKaiyuanTurnover;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanTurnover addSelective(LogKaiyuanTurnover logKaiyuanTurnover) throws Exception {
		logKaiyuanTurnoverMapper.addSelective(logKaiyuanTurnover);
		return logKaiyuanTurnover;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int delete(Map<String, Object> map) {
		return logKaiyuanTurnoverMapper.delete(map);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int update(LogKaiyuanTurnover logKaiyuanTurnover) throws Exception {
		return logKaiyuanTurnoverMapper.update(logKaiyuanTurnover);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int updateSelective(LogKaiyuanTurnover logKaiyuanTurnover) throws Exception {
		return logKaiyuanTurnoverMapper.updateSelective(logKaiyuanTurnover);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanTurnover get(Integer id) {
		LogKaiyuanTurnover logKaiyuanTurnover = logKaiyuanTurnoverMapper.get(id);
		return logKaiyuanTurnover;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public PageWrapper<LogKaiyuanTurnover> search(PageWrapper<LogKaiyuanTurnover> pageWrapper) {
		List<LogKaiyuanTurnover> logKaiyuanTurnovers = logKaiyuanTurnoverMapper.search(pageWrapper);
		pageWrapper.setList(logKaiyuanTurnovers);
		return pageWrapper;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public List<LogKaiyuanTurnover> queryList(Map<String, Object> map) {
		return logKaiyuanTurnoverMapper.queryList(map);
	}

	/**
	 * 功能说明：生成日志专用 Author：spring Date：2017/11/21 8:54
	 */
	public LogKaiyuanTurnover getLogKaiyuanTurnover(KaiyuanTurnoverType type, int fromId, int userId, String orderNo,
			BigDecimal preKaiyuanTurnover, BigDecimal KaiyuanTurnover, String remark) {
		LogKaiyuanTurnover logKaiyuanTurnover = new LogKaiyuanTurnover();
		logKaiyuanTurnover.setType(type.getCode());
		logKaiyuanTurnover.setFromId(fromId);
		logKaiyuanTurnover.setUserId(userId);
		logKaiyuanTurnover.setOrderNo(orderNo);
		logKaiyuanTurnover.setPreKaiyuan(preKaiyuanTurnover);
		logKaiyuanTurnover.setKaiyuan(KaiyuanTurnover);
		logKaiyuanTurnover.setRemark(remark);
		logKaiyuanTurnover.setDataFlag(1);
		logKaiyuanTurnover.setCreateTime(new Date());
		return logKaiyuanTurnover;
	}

	/**
	 * 功能说明：添加 新增 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuanTurnover sumKaiyuanTurnover(KaiyuanTurnoverType type, Integer fromId, Integer userId,
			String orderNo, BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuanTurnover logKaiyuanTurnover = getLogKaiyuanTurnover(type, fromId, userId, orderNo, preCash, cash,
				remark);
		logKaiyuanTurnover.setKaiyuanType(1);
		return this.add(logKaiyuanTurnover);
	}

	/**
	 * 功能说明：添加 减少 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuanTurnover subtractKaiyuanTurnover(KaiyuanTurnoverType type, Integer fromId, Integer userId,
			String orderNo, BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuanTurnover logKaiyuanTurnover = getLogKaiyuanTurnover(type, fromId, userId, orderNo, preCash, cash,
				remark);
		logKaiyuanTurnover.setKaiyuanType(0);
		return this.add(logKaiyuanTurnover);
	}

}